 @extends('layouts.admin_common') @section('content')
<div class="breadcrumbs_container">{{
	Breadcrumbs::render('admin.goods_price_master') }}</div>
<div class="system_tab_line"></div>
<script>
    $(function() {
    	changeCate($("#cateSelect").val());
    });
    function onSubmit(op,priceID){

 	   document.getElementById('price_id').value=priceID;

    	$group = $("select[name='PriceData[goods_id]']").val();
    	$settei = $("input[name='PriceData[invoice_rate]']").val();
    	$kakaku = $("input[name='PriceData[invoice_price]']").val();
		if (!$group){
			alert("商品グループを選択してください");
			return;
		}
		if (!$settei){
			alert("仕切設定を入力してください");
			return;
		}
		if (!$kakaku){
			alert("仕切を入力してください");
			return;
		}
 	   	document.getElementById('price_id').value=priceID;
        var form = document.getElementById('price');
        form.action="{{ url('admin/goodsprice') }}/"+op;
        form.submit();
    }

    function onSubmitDel(op,categoryID) {
		document.getElementById('category_id').value=categoryID;
		if (false === confirm('削除しますか？') )return;
         var form = document.getElementById('cateory');
         form.action="{{ url('admin/goodspricelist') }}/"+op;
         form.submit();
	}

    function reBack(){
    		window.location.href=('../home');
    }
    function goBack(){
        window.history.go(-1);
    }

    function remove(temp){
    	$(temp).parent().parent().remove();
    }
    function changeCate(cateid){
        if(!cateid){
			return;
        }
    	$.post("{{ url('admin/goodsprice/getGoods') }}/"+cateid,
                {'_token': '{{ csrf_token() }}'}, function(data) {
                	$("select[name='PriceData[goods_id]']").empty();
                	for(var i =0; i <data.length;i++){
                		$("select[name='PriceData[goods_id]']").append('<option value="'+data[i].goods_id+'">'+data[i].goods_name+'</option>');
                    }
                }
        )
    }
    </script>

<form class="form-inline" id="price" method="post"
	enctype="multipart/form-data">
	<table class="table-bordered" id="add_price">
		<tr>
			<td>カテゴリー</td>
			<td>商品グループ*</td>
			<td>仕切設定*</td>
			<td>仕切価格*</td>
		</tr>
		@if(!empty($price[0]))
		<tr>
			<td>
			<select name="" class="form-control" value="{{$price[0][0]->category_id}}" onchange="changeCate(this.value)">
			       @foreach($price[1] as $cataCode)
					<option value="{{$cataCode->category_id}}"
						<?php if ($cataCode->category_id == $price[0][0]->category_id) {echo 'selected';}?>>{{$cataCode->category_name}}</option>
					@endforeach
			</select></td>
			<td><select name="PriceData[goods_id]" class="form-control" value="{{$price[0][0]->goods_id}}">
					@foreach($price[2] as $goodCode)
					<option value="{{$goodCode->goods_id}}"
						<?php if ($goodCode->goods_id == $price[0][0]->goods_id) {echo 'selected';}?>>{{$goodCode->goods_name}}</option>
					@endforeach
			</select></td>
			<td><input type="text" class="form-control" name="PriceData[invoice_rate]"  value="{{$price[0][0]->invoice_rate}}"></td>
			<td><input type="text" class="form-control" name="PriceData[invoice_price]" value="{{$price[0][0]->invoice_price}}"></td>
		</tr>
	</table>
	<table class="table table-condensed">
		<tr>
			<td><input type="button" value="保存"
				class="btn btn-primary button_normal"
				onclick="onSubmit('save','{{$price[0][0]->goods_price_id}}')" /></td>
			<td><input type="button" value="キャンセル"
				class="btn btn-primary button_normal" onclick="reBack()" /></td>
			<td><input type="button" value="戻る"
				class="btn btn-primary button_normal" onclick="goBack()" /></td>
		</tr>
	</table>
	<input type="hidden" name="_token" id="csrf-token"
		value="{{ Session::token() }}" /> <input type="hidden" id="price_id"
		name="PriceData[goods_price_id]"> @else
	<tr>
		<td><select name="" class="form-control" id="cateSelect" value=""
			placeholder="カテゴリー" onchange="changeCate(this.value)">
				@foreach($price[1] as $cataCode)
				<option value="{{$cataCode->category_id}}">{{$cataCode->category_name}}</option>
				@endforeach
		</select></td>
		<td><select name="PriceData[goods_id]" class="form-control" value=""
			placeholder="商品グループ"> @foreach($price[2] as $goodCode)
				<option value="{{$goodCode->goods_id}}">{{$goodCode->goods_name}}</option>
				@endforeach
		</select></td>
		<td><input type="text" class="form-control" placeholder=""
			name="PriceData[invoice_rate]" value=""></td>
		<td><input type="text" class="form-control" placeholder=""
			name="PriceData[invoice_price]" value=""></td>
	</tr>
	</table>
	<table class="table table-condensed">
		<tr>
			<td><input type="button" value="保存"
				class="btn btn-primary button_normal" onclick="onSubmit('save','')" /></td>
			<td><input type="button" value="キャンセル"
				class="btn btn-primary button_normal" onclick="reBack()" /></td>
			<td><input type="button" value="戻る"
				class="btn btn-primary button_normal" onclick="goBack()" /></td>
		</tr>
	</table>
	<input type="hidden" name="_token" id="csrf-token"
		value="{{ Session::token() }}" /> <input type="hidden" id="price_id"
		name="PriceData[goods_price_id]"> @endif
</form>
@endsection

